Skip to content

fix: improve error handling in image validation#3832

Merged
nijel merged 1 commit into
mainfrom
validate
May 23, 2026
Merged

fix: improve error handling in image validation#3832
nijel merged 1 commit into
mainfrom
validate

Conversation

@nijel

@nijel nijel commented May 23, 2026

Copy link
Copy Markdown
Member
  • use contenxt to work with the file
  • use targettet exceptions instead of wide Exception

- use contenxt to work with the file
- use targettet exceptions instead of wide Exception
@nijel nijel requested a review from Copilot May 23, 2026 11:58
@nijel nijel self-assigned this May 23, 2026
@argos-ci

argos-ci Bot commented May 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ✅ No changes detected - May 23, 2026, 12:01 PM

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors validate_bitmap in weblate_web/models.py to use targeted Pillow exceptions instead of a broad except Exception, manages the opened image via a with block instead of try/finally, and adds a new BitmapValidationTest class covering valid PNGs, corrupted/invalid bytes, decompression-bomb headers, unsupported MIME types, and bad dimensions.

Changes:

  • Introduce a PILLOW_VALIDATION_ERRORS tuple (OSError, SyntaxError, ValueError, DecompressionBombError) and use it for the open/verify calls, removing the broad except Exception and the sys.exc_info() traceback dance.
  • Use with image: to ensure the image is closed, replacing the try/finally: image.close().
  • Add BitmapValidationTest in weblate_web/tests.py with helpers to generate and corrupt PNGs and tests for the success and error paths of validate_bitmap.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
weblate_web/models.py Narrows exception handling in validate_bitmap and switches to a context-managed image.
weblate_web/tests.py Adds BitmapValidationTest covering valid, invalid, corrupt, oversized, unsupported, and mis-sized images.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented May 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.52%. Comparing base (3a6a598) to head (859b941).
⚠️ Report is 14 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3832      +/-   ##
==========================================
+ Coverage   88.33%   88.52%   +0.18%     
==========================================
  Files          68       68              
  Lines        9507     9576      +69     
  Branches      821      824       +3     
==========================================
+ Hits         8398     8477      +79     
+ Misses        836      820      -16     
- Partials      273      279       +6     
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nijel nijel merged commit 7d17222 into main May 23, 2026
39 of 40 checks passed
@nijel nijel deleted the validate branch May 23, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants